<template>
  <cj-popup v-model="showCoupon" round position="bottom" :closeable="true" title="选择优惠券" @close="closeModal">
    <div class="c-bg-F6F7F8 c-pb40 c-pt20">
      <div class="c-ph24 c-mb30" v-if="
        isShowDeductiblePoints ||
          (isShowDiscount(vipDiscountType) ||
            isShowAgentDiscount ||
            isShowChain
          ) && !optimal"
      >
        <div class="c-fs24 c-fc-xblack c-fw500">折扣</div>
        <div class="c-flex-row c-aligni-center c-mt20" v-if="isShowDeductiblePoints">
          <div class="c-ww80 c-flex-row c-flex-shrink0">
            <div class="c-fs16 c-fw400 c-fc-xmlred c-textAlign-c c-ph6 c-hh28 c-lh30 bg-red-opacity c-br4">{{ customPointName }}</div>
          </div>
          <div class="c-fc-xblack c-fs22 c-fw400 c-flex-grow1 c-pl4" v-if="deductiblePoints && Number(deductiblePoints) > 0">{{companyAuth.integrateName1}}可抵扣{{'￥' | iosPriceFilter}}{{deductiblePoints}}</div>
        </div>
        <template v-if="!optimal">
          <div @click="goVipUp" class="c-flex-row c-aligni-start c-mt20 coms-live-iframe-none" v-if="isShowDiscount(vipDiscountType)">
            <div class="c-ww80 c-flex-row c-flex-shrink0 c-mt4">
              <div class="c-fs16 c-fw400 c-fc-xmlred c-textAlign-c c-ph6 c-hh28 c-lh30 bg-red-opacity c-br4">会员</div>
            </div>
            <div class="c-flex-grow1 c-pr32" v-if="vipDiscountType == 1">
              <!-- <span v-if="originPrice2 != ''">~{{'￥' | iosPriceFilter}}{{Number(Number(originPrice2) * vipDiscount / 100).toFixed(2)}}</span> -->
              <!-- <span v-if="originPrice2 != ''">~{{'￥' | iosPriceFilter}}{{Number(Number(originPrice2) * svipDiscount / 100).toFixed(2)}}</span> -->
              <div class="c-fc-xblack c-fs22 c-fw400 c-mb16 c-pl4" v-if="vipDiscount != 100 && vipDiscount != 0">VIP享{{parseFloat((vipDiscount / 10).toFixed(3))}}折</div>
              <div class="c-fc-xblack c-fs22 c-fw400 c-mb16 c-pl4" v-else-if="vipDiscount != 100">VIP免费</div>
              <div class="c-fc-xblack c-fs22 c-fw400 c-pl4" v-if="svipDiscount != 100 && svipDiscount != 0">SVIP享{{parseFloat((svipDiscount / 10).toFixed(3))}}折</div>
              <div class="c-fc-xblack c-fs22 c-fw400 c-pl4" v-else-if="svipDiscount != 100">SVIP免费</div>
            </div>
            <div class="c-flex-grow1 c-pr32" v-if="vipDiscountType == 2">
              <div class="c-fc-xblack c-fs22 c-fw400 c-mb16 c-pl4" v-if="vipDiscountPrice == 0">VIP免费</div>
              <div class="c-fc-xblack c-fs22 c-fw400 c-mb16 c-pl4" v-else-if="Number(vipDiscountPrice) < Number(originPrice)">VIP价：{{'￥' | iosPriceFilter}}{{Number(vipDiscountPrice).toFixed(2)}}</div>
              <div class="c-fc-xblack c-fs22 c-fw400 c-pl4" v-if="svipDiscountPrice == 0">SVIP免费</div>
              <div class="c-fc-xblack c-fs22 c-fw400 c-pl4" v-else-if="Number(svipDiscountPrice) < Number(originPrice)">SVIP价：{{'￥' | iosPriceFilter}}{{Number(svipDiscountPrice).toFixed(2)}}</div>
            </div>
            <div class="c-fs24 iconfont c-fc-gray c-ww26 c-textAlign-r c-flex-shrink0" v-if="vipType == 1 || vipType == 2 || (vipType == 4 && companyAuth.enableSvipModule == 1 && companyAuth.enableSvipSpec)">&#xe635;</div>
          </div>
          <div class="c-flex-row c-aligni-start c-mt20" v-if="isShowAgentDiscount">
            <div class="minw80 c-flex-row c-flex-shrink0 c-mt4">
              <div class="c-fs16 c-fw400 c-fc-xmlred c-textAlign-c c-ph6 c-hh28 c-lh30 bg-red-opacity c-br4" v-if="serviceName">{{serviceName}}</div>
            </div>
            <div
              class="c-fc-xblack c-fs22 c-fw400 c-flex-grow1 c-pl4"
              v-if="vipDiscountType == 1 && Number(serviceDiscount) != 100 && Number(serviceDiscount) != 0"
            >
              {{serviceName}}享{{parseFloat((serviceDiscount / 10).toFixed(3))}}折，折后{{'￥' | iosPriceFilter}}{{Number(originPrice * serviceDiscount / 100).toFixed(2)}}
              <span v-if="originPrice2 != ''">~{{'￥' | iosPriceFilter}}{{Number(Number(originPrice2) * serviceDiscount / 100).toFixed(2)}}</span>
            </div>
            <div
              class="c-fc-xblack c-fs22 c-fw400 c-flex-grow1 c-pl4"
              v-else-if="vipDiscountType == 2 && ((fromType == 'mall' && Number(originPrice) != Number(serviceDiscount) && Number(serviceDiscount) != 0) || (fromType == 'common' && Number(serviceDiscount) != 100 && Number(serviceDiscount) != 0))"
            >
              {{serviceName}}折后价{{'￥' | iosPriceFilter}}{{fromType == 'mall' ? Number(serviceDiscount).toFixed(2) : Number(originPrice * serviceDiscount / 100).toFixed(2)}}
              <span v-if="originPrice2 != ''">~{{'￥' | iosPriceFilter}}{{Number(Number(originPrice2) * serviceDiscount / 100).toFixed(2)}}</span>
            </div>
            <div class="c-fc-xblack c-fs22 c-fw400 c-flex-grow1 c-pl4" v-else-if="Number(serviceDiscount) == 0">{{serviceName}}免费</div>
          </div>
          <div class="c-flex-row c-aligni-start c-mt20" v-if="isShowChain">
            <div class="c-mww80 c-flex-row c-flex-shrink0 c-mt4">
              <div class="c-fs16 c-fw400 c-fc-xmlred c-textAlign-c c-ph6 c-hh28 c-lh30 bg-red-opacity c-br4">{{chainIdName}}</div>
            </div>
            <div class="c-flex-grow1 c-pr32">
              <div class="c-fc-xblack c-fs22 c-fw400 c-mb16 c-pl4">
                <span v-if="chainOrderBonus > 0 && (chainOrderBonus < Number(originPrice))" class="c-mr20">优惠价：{{'￥' | iosPriceFilter}}{{chainOrderBonus}}</span>
                <span v-if="reOrderBonus > 0 && (reOrderBonus < Number(originPrice))">复购价：{{'￥' | iosPriceFilter}}{{reOrderBonus}}</span>
              </div>
            </div>
          </div>
        </template>
      </div>
      <div class="c-ph24 c-mb30" v-if="optimal && (isShowDiscount(vipDiscountType) || isShowChain)">
        <div @click="goVipUp" class="c-flex-row c-aligni-start c-mt20 coms-live-iframe-none" v-if="isShowDiscount(vipDiscountType)">
          <div class="c-flex-row c-flex-shrink0 c-mt4" :class="vipType == 3 || vipType > 4 ? 'minw80' : 'c-ww80'">
            <div class="c-fs16 c-fw400 c-fc-xmlred c-textAlign-c c-ph6 c-hh28 c-lh30 bg-red-opacity c-br4">{{vipType == 3 || vipType > 4 ? idName : '会员'}}</div>
          </div>
          <div class="c-flex-grow1 c-pr32 c-fc-xblack c-fs22 c-pl4">
            {{idName}}
            <span v-if="vipDiscountType == 1 && idDiscount != 100 && idDiscount != 0">享{{Number(idDiscount / 10).toFixed(2)}}折</span>
            <span v-else-if="vipDiscountType == 2 && idPrice > 0 && idPrice != originPrice">减{{'￥' | iosPriceFilter}}{{Number(originPrice - idPrice).toFixed(2)}}元</span>
            <span v-else-if="idDiscount == 0 || idPrice == 0">免费</span>
          </div>
          <div class="c-fs24 iconfont c-fc-gray c-ww26 c-textAlign-r c-flex-shrink0" v-if="vipType == 1 || vipType == 2 || (vipType == 4 && companyAuth.enableSvipModule == 1 && companyAuth.enableSvipSpec)">&#xe635;</div>
        </div>
        <div class="c-flex-row c-aligni-start c-mt20" v-if="isShowChain">
          <div class="c-mww80 c-flex-row c-flex-shrink0 c-mt4">
            <div class="c-fs16 c-fw400 c-fc-xmlred c-textAlign-c c-ph6 c-hh28 c-lh30 bg-red-opacity c-br4">{{chainIdName}}</div>
          </div>
          <div class="c-flex-grow1 c-pr32">
            <div class="c-fc-xblack c-fs22 c-fw400 c-mb16 c-pl4">
              <span v-if="reOrderBonus > 0 && (reOrderBonus < Number(originPrice))">复购价：{{'￥' | iosPriceFilter}}{{reOrderBonus}}</span>
              <span v-else-if="chainOrderBonus > 0 && (chainOrderBonus < Number(originPrice))" class="c-mr20">优惠价：{{'￥' | iosPriceFilter}}{{chainOrderBonus}}</span>
            </div>
          </div>
        </div>
      </div>
      <div class="c-ph24 c-mb30" v-if="isShowCashback" @click="clickCashBack">
        <div class="c-fs24 c-fc-xblack c-fw500">促销</div>
        <div class="c-flex-row c-aligni-center c-mt20" v-if="!(cashBack.every(item => {return item.isDiscount == -1}))">
          <div class="c-ww80 c-flex-row c-flex-shrink0">
            <div class="c-fs16 c-fw400 c-fc-xmlred c-textAlign-c c-ph6 c-hh28 c-lh30 bg-red-opacity c-br4">满减</div>
          </div>
          <div class="c-w0 c-flex-grow1 c-flex-row c-aligni-center c-justify-sb">
            <div class="c-maxw440 c-text-ellipsis1 c-lh24 c-fc-xblack c-fs22">{{getCashBackTxt}}</div>
            <i class="iconfont c-fs24 c-fc-gray">&#xe635;</i>
          </div>
        </div>
        <div class="c-mt16 c-flex-row c-aligni-start" v-if="cashBack.filter(item => {return item.isSendPoints == 1 || item.isSendDiscount == 1 || item.isSendProd == 1}).length > 0" @click="clickCashBack">
          <div class="c-ww80 c-flex-row c-flex-shrink0">
            <div class="c-fs16 c-fw400 c-fc-xmlred c-textAlign-c c-ph6 c-hh28 c-lh30 bg-red-opacity c-br4">满赠</div>
          </div>
          <div class="c-flex-row c-flexw-wrap c-aligni-start c-h c-w0 c-flex-grow1 c-justify-sb">
            <div class="c-text-ellipsis1 c-maxw448 c-lh24 c-fc-xblack c-fs22">
              <span v-for="(item, index) in cashBack.filter(item => {return item.isSendPoints == 1 || item.isSendDiscount == 1 || item.isSendProd == 1})" :key="index">
                {{item.detail ? item.detail.title : ''}}
                <span v-for="(it, i) in item.sendProdList" :key="i">
                  送{{it.number}}件<span class="c-ml10 c-mr10 c-fc-xmlred" @click.stop="goShopDetail(it.prodId)">{{it.prodName}}</span>{{i == (item.sendProdList.length - 1) ? '' : '、'}}
                </span>{{getCashBackPresent(item)}}；
              </span>
            </div>
            <i class="iconfont c-fs24 c-fc-gray">&#xe635;</i>
          </div>
        </div>
        <div class="c-flex-row c-aligni-center c-mt20" v-if="cashBack.filter(item => {return item.isFreeShipping == 1}).length > 0">
          <div class="c-ww80 c-flex-row c-flex-shrink0">
            <div class="c-fs16 c-fw400 c-fc-xmlred c-textAlign-c c-ph6 c-hh28 c-lh30 bg-red-opacity c-br4">包邮</div>
          </div>
          <div class="c-w0 c-flex-grow1 c-flex-row c-aligni-center c-justify-sb">
            <div class="c-maxw440 c-text-ellipsis1 c-lh24 c-fc-xblack c-fs22">{{getFreeShipping}}</div>
            <i class="iconfont c-fs24 c-fc-gray">&#xe635;</i>
          </div>
        </div>
      </div>
      <div v-if="list && list.length > 0">
        <div class="c-fs22 c-fc-sblack c-fw500 c-mb20 c-ph24">优惠券</div>
        <coupon-item-com v-for="(item, index) in list" :key="index" :couponInfo="item" :source="6" class="c-mb20 c-mh24"></coupon-item-com>
        <div class="c-fs20 c-fc-sblack c-textAlign-c c-pv20" @click="getCouponList" v-if="couponIsPage || couponLoading">{{couponIsPage ? '加载更多 >' : '加载中...'}}</div>
        <loading-status-tem :pt20="true" :noData="list == null || list.length == 0" :noDataText="'暂无优惠券可领'"></loading-status-tem>
      </div>
    </div>
  </cj-popup>
</template>

<script>
import { utilJs } from "@/utils/common.js"
import loadingStatusTem from "@/components/templates/common/loadingStatusTem.vue";
import couponItemCom from "@/components/templates/couponItemCom.vue";
let isLoading = false;
const THEME_RGB_MAP = global.THEME_RGB_MAP;
export default {
  name: "CouponListCom",
  components: {
    loadingStatusTem,
    couponItemCom
  },
  props: {
    showCoupon: {
      type: Boolean,
      default: false
    },
    couponList: {
      type: Array,
      default: []
    },
    couponIsPage: {
      type: Boolean,
      default: false
    },
    couponLoading: {
      type: Boolean,
      default: false
    },
    tabIndex: {
      type: Number,
      default: -1
    },
    discountInfo: {
      type: Object,
      default: null
    },
    agentConfs: { //服务商等自定义名称
      type: Object,
      default: null
    },
    agentDisc: { //服务商等折扣
      type: Object,
      default: null
    },
    showMallPrice: { // 商城价格
      type: Number,
      default: 0
    },
    serviceName: {
      type: String,
      default: ''
    },
    vipDiscount: {
      type: Number,
      default: 100
    },
    svipDiscount: {
      type: Number,
      default: 100
    },
    deductiblePoints: {
      type: Number,
      default: 0
    },
    serviceDiscount: {
      type: Number,
      default: 100
    },
    originPrice: {
      type: Number,
      default: 0
    },
    originPrice2: {
      type: String,
      default: ''
    },
    vipTypeNum: {
      type: Number,
      default: -1
    },
    prodId: {
      type: Number,
      default: 0
    },
    prodType: {
      type: Number,
      default: 0
    },
    // 商城满减信息
    cashBack: {
      type: Array,
      default: [],
    },
    vipDiscountType: {
      type: Number,
      default: 1,
    },
    vipDiscountPrice: {
      type: Number,
      default: 0,
    },
    svipDiscountPrice: {
      type: Number,
      default: 0,
    },
    isHideDiscountInfo: {
      type: Boolean,
      default: false,
    },
    sales: {
      type: Object,
      default: null
    },
    collage: {
      type: Object,
      default: null
    },
    isChain: {
      type: Boolean,
      default: false
    },
    chainOrderBonus: {
      type: Number,
      default: 0
    },
    chainIdName: {
      type: String,
      default: ""
    },
    reOrderBonus: {
      type: Number,
      default: 0
    },
    isShowVipDiscount: { // 判断是否能展示会员、代理商折扣
      type: Boolean,
      default: true
    },
    fromType: {
      type: String,
      default: 'common'
    },
    chainInfo: {
      type: Object,
      default: null
    },
    dataInfo: {
      type: Object,
      default: null
    },
    isMarketing: { // 处于营销活动(拼团、限时折扣、好友助力、砍价)中
      type: Boolean,
      default: false
    },
  },
  beforeCreate() { },
  data() {
    return {
      list: [],
      customPointName: localStorage.getItem("customPointName"),
      companyAuth: JSON.parse(localStorage.getItem("companyAuth")),
      tabList: [{
        title: '折扣',
        index: 0,
      }, {
        title: '领券',
        index: 1,
      }],
      theme: localStorage.getItem("colorName") || "mb5_default",
      agentState: {},
      vipType: localStorage.getItem("vipType" + localStorage.getItem("userId")) ? localStorage.getItem("vipType" + localStorage.getItem("userId")) : 1,
      discountPrice: 0,
      chainPrice: 0,
      ckFrom: global.ckFrom,
    };
  },
  computed: {
    // 营销活动中存在两种最低价格（最低价格不是营销价格）
    isInMarketTwoPrice() {
      if (this.dataInfo.prodType == this.ckFrom.shopping) {
        return this.dataInfo.isInMarketTwoPrice || false
      }
      let sales = this.dataInfo && this.dataInfo.prodType == this.ckFrom.datum ? this.dataInfo.flashSales : this.dataInfo.sales;
      return this.optimal && !((sales && this.optimal.optimalPriceType != 101) || (this.dataInfo.bargain && ((this.dataInfo.bargain.status == 1 &&
            this.dataInfo.bargain.isPreheat == 1) || this.dataInfo.bargain.status == 2)) || (this.dataInfo.collage && (this.dataInfo.collage.status == 2 || this.dataInfo.collage.status == 1)) || (this.dataInfo.isFriendHelper)) ? false : true
    },
    // 最优价格对象
    optimal() {
      // optimalPriceType：1 产品本身价格 2 vip价格 3 svip价格 4 服务商 101 限时购 102 拼团 112 砍价  10 链动会员 20 链动代理商 99 链动复购
      return this.dataInfo ? this.dataInfo.optimal : null;
    },
    // 判断是否显示代理商折扣
    isShowAgentDiscount() {
      return !this.$isWxAppIos() && !this.isShowChain && this.isShowVipDiscount && this.serviceName && this.serviceDiscount != null && (this.vipType == 3 || this.vipType > 4) &&
        (this.fromType != 'mall' || (this.fromType == 'mall' && this.isHideDiscountInfo == false)) &&
        ((this.vipDiscountType == 1 && this.serviceDiscount < 100) || (this.vipDiscountType == 2 && Number(this.originPrice) != Number(this.serviceDiscount)))
    },
    // 判断是否展示vip/svip折扣
    isShowDiscount() {
      return function(vipDiscountType) {
        if (this.optimal) {
          let showDisPrice = [2, 3, 4].includes(this.optimal.optimalPriceType) && !this.isMarketing;
          if (this.isInMarketTwoPrice) {
            this.discountPrice = this.vipDiscountType == 1 ? Number(this.dataInfo.price * this.idDiscount / 100) : this.idPrice;
            this.chainPrice = this.chainInfo && this.chainInfo.isChainProd ?
                              (this.chainInfo.enableReorderDiscount == 1 && this.chainInfo.isReorder ? this.chainInfo.reorderBonus : this.chainInfo.enableOrderDiscount == 1 ? this.chainInfo.orderBonus : this.dataInfo.price) :
                              this.dataInfo.price;
            showDisPrice = (this.chainInfo && this.chainInfo.isChainProd) ? this.discountPrice * 1 < this.chainPrice * 1 : this.discountPrice * 1 < this.dataInfo.price * 1;
          }
          return !this.$isWxAppIos() && this.optimal && showDisPrice
        } else {
          if (vipDiscountType == 1) {
            return !this.$isWxAppIos() && !this.sales && !this.isShowChain && this.isShowVipDiscount && ((this.vipDiscount != null && this.vipDiscount < 100) || (this.svipDiscount != null && this.svipDiscount < 100))
          } else {
            return !this.$isWxAppIos() && !this.sales && !this.isShowChain && this.isShowVipDiscount && ((this.vipDiscountPrice < this.originPrice) || (this.svipDiscountPrice < this.originPrice))
          }
        }
      }
    },
    // 判断是否展示积分
    isShowCashback() {
      return this.cashBack && this.cashBack.length > 0;
    },
    // 判断是否展示积分
    isShowDeductiblePoints() {
      if (!this.optimal) {
        return this.deductiblePoints > 0 && this.companyAuth.enablePoints == 1 && !this.sales;
      } else {
        let sales = this.dataInfo && this.dataInfo.prodType == this.ckFrom.datum ? this.dataInfo.flashSales : (this.dataInfo && this.dataInfo.sales ? this.dataInfo.sales : null);
        return this.deductiblePoints > 0 &&
          (
            (this.dataInfo.prodType != this.ckFrom.shopping && ((sales && this.optimal && this.optimal.optimalPriceType != 101) || !sales)) ||
            (this.dataInfo.prodType == this.ckFrom.shopping && this.optimal && this.optimal.optimalPriceType != 101)
          )
      }
    },
    // 展示链动
    isShowChain() {
      if (this.optimal) {
        let showChainPrice = [10, 20, 99].includes(this.optimal.optimalPriceType) && !this.isMarketing;
        if (this.isInMarketTwoPrice) {
          this.discountPrice = this.vipDiscountType == 1 ? Number(this.dataInfo.price * this.idDiscount / 100) : this.idPrice;
          this.chainPrice = this.chainInfo && this.chainInfo.isChainProd ?
                            (this.chainInfo.enableReorderDiscount == 1 && this.chainInfo.isReorder ? this.chainInfo.reorderBonus : this.chainInfo.enableOrderDiscount == 1 ? this.chainInfo.orderBonus : this.dataInfo.price) :
                            this.dataInfo.price;
          showChainPrice = (this.chainInfo && this.chainInfo.isChainProd) ? this.chainPrice * 1 <= this.discountPrice * 1 : this.chainPrice * 1 <= this.dataInfo.price * 1;
        }
        return !this.$isWxAppIos() && showChainPrice && ((this.chainOrderBonus > 0 && (this.chainOrderBonus < Number(this.originPrice))) || (this.reOrderBonus > 0 && (this.reOrderBonus < Number(this.originPrice))))
      } else {
        return !this.$isWxAppIos() && !this.sales && this.isChain && ((this.chainOrderBonus > 0 && (this.chainOrderBonus < Number(this.originPrice))) || (this.reOrderBonus > 0 && (this.reOrderBonus < Number(this.originPrice))))
      }
    },
    // 满减活动满减信息
    getCashBackTxt() {
      let txt = '';
      this.cashBack.forEach((item, index) => {
        if (item.isDiscount == 1) {
          txt = txt + item.detail.title + item.detail.amount + (index == (this.cashBack.length - 1) ? '' : '；');
        }
      })
      return txt;
    },
    // 显示"、送x张无门槛券、x张折扣券、送x积分"
    getCashBackPresent() {
      return function(discountInfo) {
        let sendDiscount = '';
        let sendPoints = '';
        if (discountInfo.isSendDiscount == 1) {
          sendDiscount = `${discountInfo.isSendProd == 1 ? '、' : ''}送`
          discountInfo.sendDiscountList .forEach((item, index) => {
              sendDiscount = `${sendDiscount}${item.number}张${item.redeemCodeType == 1 ? '兑换码' : (item.redeemCodeType == 2 ? '代金券' : (item.redeemCodeType == 3 ? '满减券' : (item.redeemCodeType == 4 ? '抵价券' : '折扣券')))}${index == (discountInfo.sendDiscountList.length - 1) ? '' : '、'}`
          })
        }
        if (discountInfo.isSendPoints == 1) {
          sendPoints = `${discountInfo.isSendDiscount == 1 || discountInfo.isSendProd == 1 ? '、' : ''}送${discountInfo.points}${this.customPointName}`;
        }
        return sendDiscount + sendPoints;
      }
    },
    // 满减活动包邮信息
    getFreeShipping() {
      let txt = '';
      let list = this.cashBack.filter(item => {return item.isFreeShipping == 1});
      list.forEach((item, index) => {
        txt = txt + item.detail.title + item.detail.ship + (index == (list.length - 1) ? '' : '；')
      })
      return txt;
    },
    styleColor() {
      return `backgroundColor: rgba(${THEME_RGB_MAP[this.theme]}, 0.1)`
    },
  },
  watch: {
    dataInfo: {
      handler(newVal) {
        const dataInfo = JSON.parse(JSON.stringify(newVal));
        const vipType = this.vipType;
        if (dataInfo) {
          this.vipDiscount = Number(dataInfo.vipDiscount);
          this.svipDiscount = Number(dataInfo.svipDiscount);
          this.vipDiscountPrice = Number(dataInfo.vipDiscountPrice);
          this.svipDiscountPrice = Number(dataInfo.svipDiscountPrice);
          this.originPrice = Number(dataInfo.price);
          this.deductiblePoints = Number(dataInfo.deductiblePoints);
          // 商城跟其他模块的关于代理商折扣vipDiscountType判断不一样 其他模块的commonProdInfo.agentDiscount都是百分比
          this.vipDiscountType = (dataInfo.prodType != this.ckFrom.shopping && (vipType == 3 || vipType > 4) && dataInfo.commonProdInfo && dataInfo.commonProdInfo.agentDiscount < 100) ? 1 : (dataInfo.vipDiscountType ? Number(dataInfo.vipDiscountType) : 1);
          this.sales = dataInfo.sales ? dataInfo.sales : this.sales;
          let custNameMap = utilJs.getCustNameMap();
          const agentDiscount = dataInfo.prodType != this.ckFrom.shopping ?
                                (dataInfo.commonProdInfo && dataInfo.commonProdInfo.agentDiscount < 100 ? dataInfo.commonProdInfo.agentDiscount : 100) :
                                (dataInfo.commonProdInfo && dataInfo.commonProdInfo.agentDiscount ? dataInfo.commonProdInfo.agentDiscount : this.vipDiscountType == 1 ? 100 : dataInfo.price);
          const svipDiscount = dataInfo.svipDiscount < 100 ? dataInfo.svipDiscount : 100;
          const vipDiscount = dataInfo.vipDiscount < 100 ? dataInfo.vipDiscount : 100;
          if (this.optimal && (!this.isMarketing || (!this.isInMarketTwoPrice && this.isMarketing))) {
            const optimal = dataInfo.optimal;
            this.idName = optimal.optimalPriceType == 2 ? 'VIP' : optimal.optimalPriceType == 3 ? 'SVIP' : optimal.optimalPriceType == 4 ? custNameMap[vipType] : '';
            this.idPrice = optimal.optimalPrice;
            this.idDiscount = optimal.optimalPriceType == 2 ? vipDiscount : optimal.optimalPriceType == 3 ? svipDiscount : optimal.optimalPriceType == 4 ? agentDiscount : 100;
          } else {
            custNameMap[1] = 'VIP';
            this.idName = custNameMap[vipType];
            // 商城跟其他模块字段不一致
            if (dataInfo.prodType == this.ckFrom.shopping) {
              this.idPrice = dataInfo.vipDiscountType == 2 ? (
                (vipType == 4 && Number(dataInfo.svipDiscount) < Number(dataInfo.price))
                  ? Number(dataInfo.svipDiscount)
                  :
                (vipType == 2 && Number(dataInfo.vipDiscount) < Number(dataInfo.price))
                  ? Number(dataInfo.vipDiscount)
                  :
                ((vipType == 3 || vipType > 4) && Number(dataInfo.commonProdInfo.agentDiscount) < Number(dataInfo.price))
                  ? Number(dataInfo.commonProdInfo.agentDiscount) : Number(dataInfo.price)
              ) : Number(dataInfo.price);
            } else {
              this.idPrice = dataInfo.vipDiscountType == 2 ? (
                (vipType == 4 && Number(dataInfo.svipDiscountPrice) < Number(dataInfo.price))
                  ? Number(dataInfo.svipDiscountPrice)
                  :
                (vipType == 2 && Number(dataInfo.vipDiscountPrice) < Number(dataInfo.price))
                  ? Number(dataInfo.vipDiscountPrice)
                  : Number(dataInfo.price)
              ) : Number(dataInfo.price);
            }
            this.idDiscount = (vipType == 3 || vipType > 4) && agentDiscount < 100 ? agentDiscount :
                    vipType == 4 && svipDiscount < 100 ? svipDiscount :
                    ((((vipType == 1 || vipType == 2) && !dataInfo.optimal) || (vipType == 2 && dataInfo.optimal)) && vipDiscount < 100) ? vipDiscount : 100;
            this.discountPrice = this.vipDiscountType == 1 ? Number(this.dataInfo.price * this.idDiscount / 100) : this.idPrice;
            this.chainPrice = this.chainInfo && this.chainInfo.isChainProd ?
                              (this.chainInfo.enableReorderDiscount == 1 && this.chainInfo.isReorder ? this.chainInfo.reorderBonus : this.chainInfo.enableOrderDiscount == 1 ? this.chainInfo.orderBonus : this.dataInfo.price) :
                              this.dataInfo.price;
          }
        }
      },
      immediate: true,
      deep: true
    },
    chainInfo: {
      handler(newVal) {
        const chainInfo = JSON.parse(JSON.stringify(newVal));
        if (chainInfo) {
          this.isChain = chainInfo.isChainProd;
          this.chainOrderBonus = chainInfo.enableOrderDiscount == 1 ? chainInfo.orderBonus : 0;
          this.reOrderBonus = chainInfo.enableReorderDiscount == 1 && chainInfo.isReorder == 1 ? chainInfo.reorderBonus : 0;
          this.chainIdName = chainInfo.enableReorderDiscount == 1 && chainInfo.isReorder ?
                  '复购价' : chainInfo.userType == 1 ? '普通用户' : chainInfo.userType2Name[chainInfo.userType];
        }
      },
      immediate: true,
      deep: true
    },
    tabIndex(val) {
      this.tabIndex = val;
    },
    couponList(val) {
      this.list = val;
    },
  },
  methods: {
    // 跳转到商品详情
    goShopDetail(shopNo) {
      this.$routerGo(this, "push", {
        path: "/mall/shopDetail/shopDetail",
        query: { shopNo: shopNo }
      });
    },
    clickCashBack() {
      this.$emit('clickCashBack');
    },
    goVipUp: function () {
      if (this.vipType == 1 || this.vipType == 2 || (this.vipType == 4 && this.companyAuth.enableSvipModule == 1 && this.companyAuth.enableSvipSpec)) {
        this.$routerGo(this, "push", { path: "/member/vip/vipUp" });
      }
    },
    closeModal: function (e) {
      this.$emit("closeModal");
    },
    getCouponList: function (e) {
      this.$emit("getCouponList");
    },
    // getCoupon: function (redeemCodeId, cIndex) {
    //   this.$emit("getCoupon", redeemCodeId, cIndex);
    // },
    //领取优惠券
    getCoupon(couponId, cIndex) {
      if (
        localStorage.getItem("enableBindPhoneInRedeemCode") == 1 &&
        !localStorage.getItem("uMobile")
      ) {
        utilJs.goBindMobile();
      } else {
        if (isLoading) {
          return;
        }
        isLoading = true;
        let $this = this;
        let postData = {};
        if ($this.list[cIndex].type == 1) {
          postData = {
            prodId: this.prodId,
            prodType: this.prodType
          }
        }
        postData.source = 6; //领取来源：6(详情页)
        utilJs.postMethod(
          global.apiurl + "redeemCodes/collectRedeemCodeId/" + couponId,
          postData,
          function (res) {
            isLoading = false;
            if (res.status == 8 || res.status == 15) {
              $this.list[cIndex].hasReceive++;
              $this.$showCjToast({
                text: '领取成功',
                type: 'success',
              }).then(() => {
                if ($this.list[cIndex].type == 1) {
                  window.location.reload();
                }
              })
            } else if (res.status == 13) {
              utilJs.goBindMobile();
            } else {
              $this.$showCjToast({
                text: res.detail,
                type: 'warn'
              });
            }
          }
        );
      }
    },
  },
  activated() {
    this.companyAuth = JSON.parse(localStorage.getItem("companyAuth"));
    this.agentState = utilJs.getCustNameMap();
  },
  deactivated() { }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.coupon-left {
  background: -webkit-linear-gradient(314deg, #FF8165, #FF4A35);
}
.exchange-left {
  background: -webkit-linear-gradient(314deg, #F5D199, #D5A357);

}
.bg-red-opacity {
  background: rgba(255,48,12,0.1);
}
.minw80 {
  min-width: 2rem;
}
.c-maxw448 {
    max-width: 11.2rem;
}
.c-fc-FF4A35 {
  color: #FF4A35;
}
.c-bg-F6F7F8 {
  background-color: #F6F7F8;
}
.points::before{
  content: "";
  background-color: #F6F7F8;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  top: -6px;
  left: -6px;
  position: absolute;
}
.points::after{
  content: "";
  background-color: #F6F7F8;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  bottom: -6px;
  left: -6px;
  position: absolute;
}
.opacity5 {
  opacity: 0.5;
}
</style>
